#ifndef _OBJECTMANAGER_H_
#define _OBJECTMANAGER_H_

#include "GamePlayer.h"
#include "GameEnemy.h"
#include "GameTeam.h"
#include "netSocket.h"


// max player
#define PLAYER_CACHE_COUNT 5000 
#define ENEMY_CACHE_COUNT 50000 

// struct UserRoleInfo
// {
// 	string account;
// 	string name;
// 	fint32 money;
// 	fint32 gender;
// 	fint32 type;
// 
// 	UserRoleInfo()
// 	:	type( GameCreature::GCTGUEST ) ,
// 		money( 0 ) , 
// 		gender( 0 )
// 	{
// 
// 	}
// };

// typedef map< fint32 , UserRoleInfo > UserRoleInfoMap;
// typedef map< fint32 , UserRoleInfo >::iterator UserRoleInfoMapIter;



class CreatureManager : public baseSingle< CreatureManager >
{
public:

	CreatureManager();
	~CreatureManager();


	fvoid							Init();

	fvoid							Release();


	GamePlayer*						CreatPlayer();

	// game logic use
	GamePlayer*						GetPlayer( fint32 guid );

	// net use
	GamePlayer*						GetPlayer( netSocket* socket );

	fvoid							ReleasePlayer( GamePlayer* player );
	fvoid							RemovePlayer( GamePlayer* player );

	fbool							SetGUID( fint32 guid , GamePlayer* player );
	fbool							SetSocket( netSocket* socket , GamePlayer* player );
	fvoid							RemoveSocket( GamePlayer* player );

	fvoid							AddMsgToAll( netMsgHead* msg );
	fvoid							SendMsgToAll();
	fvoid							Close();

	fint32							GetFreePlayerCount();
	fint32							GetSocketPlayerCount();
	fint32							GetPlayerCount();
	fint32							GetGuestount();


// 	fvoid							SetUserRoleInfo( fint32 guid , const UserRoleInfo& info );
// 	UserRoleInfo&					GetUserRoleInfo( fint32 guid );


	//////////////////////////////////////////////////////////////////////////
	// enemy
	
	fvoid							LoadPetPhoto( const fbyte* path );

	fvoid							LoadEnemyBase( const fbyte* path );
	fvoid							LoadEnemy( const fbyte* path );
	fvoid							LoadEnemyGroup( const fbyte* path );

	GameEnemyBase*					GetEnemyBase( fint32 id );
	GameEnemy*						GetEnemy( fint32 id );
	GameEnemyGroup*					GetEnemyGroup( fint32 id );


	//////////////////////////////////////////////////////////////////////////
	// team

	GameTeam*						CreatTeam();
	fvoid							RemoveTeam( GameTeam* team );

protected:
private:

	typedef list< GameTeam* >::iterator GameTeamListIter;
	list< GameTeam* >				mFreeTeamList;

	//UserRoleInfoMap					mUserRoleInfo;

	GamePlayer*						mPlayerCache[PLAYER_CACHE_COUNT];

	// db read and write thread use.
	typedef list< GamePlayer* >::iterator FreePlayerIter;
	list< GamePlayer* >			mFreePlayer;

	typedef map< fint32 , GamePlayer* > GamePlayerMap;
	typedef map< fint32 , GamePlayer* >::iterator GamePlayerMapIter;
	map< fint32 , GamePlayer* >		mGamePlayerMap;

	typedef map< netSocket* , GamePlayer* > GamePlayerSocketsMap;
	typedef map< netSocket* , GamePlayer* >::iterator GamePlayerSocketsMapIter;
	GamePlayerSocketsMap	mGamePlayerSocketsMap;




	typedef map< fint32 , GameEnemyBase > GameEnemyBaseMap;
	typedef map< fint32 , GameEnemyBase >::iterator GameEnemyBaseMapIter;
	GameEnemyBaseMap	mGameEnemyBaseMap;


	typedef map< fint32 , GameEnemy > GameEnemyMap;
	typedef map< fint32 , GameEnemy >::iterator GameEnemyMapIter;
	GameEnemyMap	mGameEnemyMap;

	typedef map< fint32 , GameEnemyGroup > GameEnemyGroupMap;
	typedef map< fint32 , GameEnemyGroup >::iterator GameEnemyGroupMapIter;
	GameEnemyGroupMap	mGameEnemyGroupMap;



};

extern CreatureManager* gCreatureManager;

struct PetPhotoData 
{
	fint16 id;
	fint16 photo;
};
extern map< fint32 , PetPhotoData > gMapPetPhotoID;

#endif

